package com.cn.sl.server.api.system.user.model.dto

import com.cn.sl.server.api.system.department.model.dto.DepartmentDto
import com.cn.sl.server.api.system.file.model.dto.SysFileDto
import com.cn.sl.server.api.system.user.model.entity.AdminUserEntity
import io.swagger.v3.oas.annotations.media.Schema

/**
 * 用户信息
 *
 * @author 阮雪峰
 */
@Schema(description = "登录用户信息")
data class AdminUserInfoDto(
    /**
     * 主键
     */
    @field:Schema(description = "用户id")
    val id: Long,
    @field:Schema(description = "头像id")
    val avatarId: Long?,
    @field:Schema(description = "头像")
    val avatarFile: SysFileDto?,
    /**
     * 登录名
     */
    @field:Schema(description = "用户名")
    val username: String,
    @field:Schema(description = "联系电话")
    val phone: String?,
    @field:Schema(description = "角色")
    val roles: List<String> = listOf(),
    @field:Schema(description = "部门id")
    val departmentId: Long?,
    @field:Schema(description = "部门")
    val department: DepartmentDto?,
) {
    constructor(entity: AdminUserEntity) : this(
        entity.id,
        entity.avatarId,
        entity.avatar?.let { SysFileDto(it) },
        entity.username,
        entity.phone,
        entity.roles.map { it.name },
        entity.departmentId,
        entity.department?.let { DepartmentDto(it) }
    )

    val avatar: String?
        get() {
            return avatarFile?.fullUrl
        }
}